#ifndef __DATA_PARSER_H__
#define __DATA_PARSER_H__
#include <cjson/cJSON.h>
enum INFO_CODE{
    EXIT,
    LOGIN,
    LOGOUT,
    ACCEPTED,
    ERROR
};

/**
 * @Description: 
 *      For Client.
 *      Encode the log in information (char* formate) to cJSON* that the socket transfers.
 * @Parameters: 
 *      char* user_name: the username of the user who call this function.
 *      char* user_ip: the user's IP address.
 *      char* password: the password user entered.
 *      cJSON* login_info: a pointer to a cJson struct, which stores the previouse information.
 *                         Warning: cJSON pointer must be created by "cJSON_CreateObject" function.
 * @Return: 
 *      Return ACCEPTED for parsing info successfully, other info code for Exception.
 * @Throw: 
 */
int encodeLoginInfo(char *user_name, char *password, cJSON *login_info);

/**
 * @Description: 
 *      For Database.
 *      Parse the log in information (cJSON formate) to char* that the database uses.
 * @Parameters: 
 *      cJSON* login_info: a pointer to a cJson struct, which is passed to database by the 
 *          socket server.
 *      char* user_name: Provided by DB, stores username parsed from cJSON.
 *      char* user_ip: Provided by DB, stores user_ip parsed from cJSON.
 *      char* password: Provided by DB, stores password parsed from cJSON.
 * @Return: 
 *      Return ACCEPTED for parsing info successfully, other info code for Exception. (See in Throw)
 * @Throw: 
 *      DB_CJSON_PARSE_ERR : when passed cJSON has the error structure.
 */
int parseLoginInfo(cJSON *login_info, char *user_name, char *password);

#endif